home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_04
/
allison
/
operate.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-06
|
527b
|
30 lines
LISTING 10 - operator+ and operator<< for a complex number data
type
#include <iostream.h>
struct complex
{
double real, imag;
complex(double = 0.0, double = 0.0);
};
complex::complex(double r, double i)
{
real = r;
imag = i;
}
inline ostream& operator<<(ostream &os, const complex &c)
{
os << '(' << c.real << ',' << c.imag << ')';
return os;
}
inline complex operator+(const complex &c1, const complex &c2)
{
return complex(c1.real+c2.real,c1.imag+c2.imag);
}